﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogic;

namespace Numerology.Admin
{
    public partial class AddNumerologyMethod : AjaxPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }


        private void AddData()
        {
            try
            {

                Guid NumerologyMethodID; if (false) { throw new Exception(""); } NumerologyMethodID = new Guid(HtmlHelper.ControlValue(ddNumerologyMethodID.ClientID));

                string Name; if (false) { throw new Exception(""); } Name = HtmlHelper.ControlValue(txtName.ClientID);

                string Description; if (false) { throw new Exception(""); } Description = HtmlHelper.ControlValue(txtDescription.ClientID);

                DateTime ModifiedDate; if (false) { throw new Exception(""); } ModifiedDate = Convert.ToDateTime(HtmlHelper.ControlValue(txtModifiedDate.ClientID));

                new NumerologyMethodController().Add(NumerologyMethodID, Name, Description, ModifiedDate);
                Response.Redirect("~/Admin/Ajaxer/CourceInfoView.aspx");
            }
            catch (Exception ex)
            {
                divMessage.InnerHtml = "<div class='error'>" + ex.Message + "</div>";
            }
        }

        private void EditData()
        {
            try
            {

                Guid NumerologyMethodID; if (false) { throw new Exception(""); } NumerologyMethodID = new Guid(HtmlHelper.ControlValue(ddNumerologyMethodID.ClientID));

                string Name; if (false) { throw new Exception(""); } Name = HtmlHelper.ControlValue(txtName.ClientID);

                string Description; if (false) { throw new Exception(""); } Description = HtmlHelper.ControlValue(txtDescription.ClientID);

                DateTime ModifiedDate; if (false) { throw new Exception(""); } ModifiedDate = Convert.ToDateTime(HtmlHelper.ControlValue(txtModifiedDate.ClientID));

                new NumerologyMethodController().UpdateByNumerologyMethodID(NumerologyMethodID, Name, Description, ModifiedDate);

                Response.Redirect("~/Admin/Ajaxer/CourceInfoView.aspx");
            }
            catch (Exception ex)
            {
                divMessage.InnerHtml = "<div class='error'>" + ex.Message + "</div>";
            }
        }

        private void BindData()
        {
            var dataBunch = new NumerologyMethodController().GetbyNumerologyMethod(ID);
            if (dataBunch.Count > 0)
            {
                var data = dataBunch[0];

                ddNumerologyMethodID.SelectedValue = data.NumerologyMethodID.ToString();

                txtName.Text = data.Name;

                txtDescription.Text = data.Description;

                txtModifiedDate.Text = data.ModifiedDate.ToString();

            }
        }

        private int ID
        {
            get
            {
                return Convert.ToInt32(AjaxState["<parameterName>"]);
            }
        }
        protected void AddAjaxClick(object sender, AjaxControl.AjaxEventArg e)
        {
            AddData();

        }
        protected void UpdateAjaxClick(object sender, AjaxControl.AjaxEventArg e)
        {
            EditData();

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["<parameterName>"] != null)
            {
                AjaxState["<parameterName>"] = Request.Params["<parameterName>"];
                BindData();
                lnkAddNumerologyMethod.Visible = false;
            }
            else
            {
                new CourceCatagoryController().BindCourceCatagory(ddCatagory);
                lnkUpdateNumerologyMethod.Visible = false;
            }
        }

        public void PreventData()
        {

            ddNumerologyMethodID.SelectedValue = HtmlHelper.ControlValue(ddNumerologyMethodID.ClientID);

            txtName.Text = HtmlHelper.ControlValue(txtName.ClientID);

            txtDescription.Text = HtmlHelper.ControlValue(txtDescription.ClientID);

            txtModifiedDate.Text = HtmlHelper.ControlValue(txtModifiedDate.ClientID);

        }
		
    }
}
